﻿using Abp.Application.Services.Dto;
using Abp.Web.Mvc.Authorization;
using Akso.Authorization;
using Akso.Codes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using Akso.Web.Areas.BasicDataModule.Models.Codes;

namespace Akso.Web.Areas.BasicDataModule.Controllers
{
    public class CodesController : Controller
    {
        private readonly ICodeAppService _codesAppService;
        public CodesController(ICodeAppService codesAppService)
        {
            _codesAppService = codesAppService;
        }
        public ActionResult Index()
        {
            string d = Request.QueryString["codeGroupId"];
            return View();
        }
        /// <summary>
        /// 为新增、编辑数据页面加载数据，弹出修改页面框。
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [AbpMvcAuthorize(AppPermissions.Pages_BasicDataModule_Codes_Create, AppPermissions.Pages_BasicDataModule_Codes_Edit)]
        public async Task<PartialViewResult> CreateOrEditModal(Guid? id,Guid codeGroupID)
        {
            
            var output = await _codesAppService.GetObjectForEdit(new NullableIdDto<Guid> { Id = id });
            if(codeGroupID!=null)
                output.Code.CodeGroupID = codeGroupID;
            var viewModel = new CreateOrEditCodeModalViewModel(output);

            return PartialView("_CreateOrEditModal", viewModel);
        }
    }
}